<?php
/**
 * Created by PhpStorm.
 * User: ytlmi
 * Date: 2018/3/12
 * Time: 10:37
 */

namespace org\util\wordTool\example;

use org\util\forensicTool\ForensicCalculate;

class Report2l extends ReportQz
{
    /**
     * @throws \Exception
     */
    protected function addDetectionTable()
    {
        $roleGroup = $this->makeRoleGroup();

        //设置单元格宽度
        $positionMap=['first'=>self::FIRST_ROW_STYLE,'mid'=>self::MID_ROW_STYLE,'last'=>self::LAST_ROW_STYLE];
        $width = [2000, 2000, 2000, 2000];

        //每个亲代与每个子代生成对比表格
        $tableIndex=0;
        foreach ($roleGroup[1] as $child) {
            foreach ($roleGroup[0] as $parent){
                $tableIndex++;
                $calResult=ForensicCalculate::instance()
                    ->setCaseType($this->caseData['case_type'])
                    ->setGenotypeF($this->caseData['samples'][$parent]['genotype'])
                    ->setGenotypeC($this->caseData['samples'][$child]['genotype'])
                    ->setFrequency($this->frequency)
                    ->setMutation($this->mutation)
                    ->calculate();//计算
                $childSampleName=$this->caseData['samples'][$child]['sample_name'];//样品名
                $parentSampleName=$this->caseData['samples'][$parent]['sample_name'];//样品名
                $arrMarker=array_keys($calResult);//全部基因座
                $tableDes='表'.$tableIndex.'：'.$childSampleName.'和'.$parentSampleName.'号检材STR基因座的基因分型结果';//表头
                $tableHead=['基因座',$childSampleName,$parentSampleName,'亲权指数'];//第一行
                $this->body->addPr($tableDes,self::TABLE_DES_FONT,self::TEXT_TAB);
                $table = $this->body->addTable(self::TABLE_STYLE);
                $table->addSimpleRow($tableHead, $width, self::TABLE_FONT, $positionMap['first']);
                foreach ($calResult as $marker=>$result) {
                    $pi=isset($result[0]) ? sprintf("%.2f",$result[0]) : '-';//无计算结果时用“-”代替
                    $alleleC=$this->caseData['samples'][$child]['genotype'][$marker];//孩子在当前基因座的基因型
                    $alleleP=$this->caseData['samples'][$parent]['genotype'][$marker];//亲代基因型
                    $content=[$marker,$alleleC[0].','.$alleleC[1],$alleleP[0].','.$alleleP[1],$pi];
                    $position = $marker==end($arrMarker) ? 'last' : 'mid';
                    $table->addSimpleRow($content, $width, self::TABLE_FONT, $positionMap[$position]);
                }
            }
        }
    }
}